1 package net.sourceforge.selfesteem;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7 public class CompositeNode implements Node {
8 protected String _name;
9 protected List _list = new ArrayList();
10
11 public CompositeNode(String name) {
12 _name = name;
13 }
14
15 public boolean isPassing() {
16 if (_list.size() == 0) return false;
17
18 for (Iterator i = _list.iterator(); i.hasNext();) {
19 if (!((Node) i.next()).isPassing()) return false;
20 }
21 return true;
22 }
23
24 public String getName() {
25 return _name;
26 }
27
28 public void add(Node node) {
29 _list.add(node);
30 }
31
32 public Node get(int i) {
33 return (Node) _list.get(i);
34 }
35
36 public Iterator iterator() {
37 return _list.iterator();
38 }
39
40 protected int getPassingChildCount() {
41 int count = 0;
42 for (Iterator i = _list.iterator(); i.hasNext();) {
43 if (((Node) i.next()).isPassing()) count++;
44 }
45 return count;
46 }
47
48 public String toString() {
49 return getName();
50 }
51
52 protected String percent(String name) {
53 int pass = getPassingChildCount();
54 int total = _list.size();
55 return pass + " / " + total + " " + name + " passed - " + (total != 0 ? pass * 100 / total : 0) + "%";
56 }
57
58 public void serialize(Serializer serializer, int level) {
59 serializer.addLine(level, toString());
60 for (Iterator i = iterator(); i.hasNext();) {
61 Node node = (Node) i.next();
62 node.serialize(serializer, level + 1);
63 }
64 }
65 }
This page was automatically generated by Maven